home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 8 / FM Towns Free Software Collection 8.iso / t_os / wink24h / src / rsb2.c < prev    next >
Text File  |  1994-06-01  |  28KB  |  1,077 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <ctype.h>
  4. #include    "defs.h"
  5. #ifdef  TOWNS
  6. #include    <time.h>
  7. #include    <egb.h>
  8. #include    <fmcfrb.h>
  9. #include    <msdos.cf>
  10. #include    <rs.h>
  11. #endif
  12.  
  13. #define    MENU_MAX    11
  14.  
  15. #define    SJIS        0
  16. #define    EUC        1
  17. #define JIS        2
  18.  
  19. #define    BUF_SIZ    4096        /* looking RSBLIB.ASM */
  20.  
  21. extern UCHAR *cvram;
  22. extern char  *SPCSTR;
  23. extern int   Line_no;
  24. extern short ReWrt_flg;
  25. extern int   TrmCol;
  26. extern int   DspCnt;
  27.  
  28. extern char *kanji_chk();
  29. extern BOOL Input();
  30. extern void Dmy_form();
  31. extern void wrtstr();
  32. extern void Soft_Timer();
  33. extern int  kbhit();
  34. extern int  Get_key();
  35. extern void BakPut();
  36. extern void Dsp_vram();
  37. extern int  Sel_menu();
  38. extern void Dsp_free();
  39. extern int  strlen();
  40. extern void strcpy();
  41. extern void Dsp_vram_flash();
  42. extern void BP_Term_ENQ();
  43. extern void BP_DLE_Seen();
  44. extern void ins_chr();
  45. extern void Set_vram();
  46. extern void Del_buf();
  47. extern void Cur_btm_file();
  48. extern int  File_sel();
  49. extern void Cut_buf();
  50. extern int  Undo_cpy();
  51. extern void memset();
  52. extern int  Con_init();
  53. extern void CD_menu();
  54. extern void Con_end();
  55. extern void Dsp_PFKEY();
  56. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  57. extern int cd_m_stat;
  58. /* ---------------------------------------------------------- */
  59.  
  60.        int  port=0,bps=0x05;
  61. static int  mode=0x11,brk=0,swait=0,KanMod=0;
  62. static int  Down_flg=FALSE,Line_flg=FALSE,Line_X=0;
  63. static FILE *Down_fp=NULL;
  64. static int  Flaing=FALSE;
  65. static unsigned brktime[]={ 25,50,100,200 };
  66. static int  swtime[]={1,5000,10000,20000,50000 };
  67.  
  68. static    char    para[20];
  69. static    char    buffer[65536];       /*    受信バッファ    */
  70.  
  71. static int      cons_od1=0;
  72. static int      cons_od2=0;
  73. static int      cons_kan=0;
  74. static int      cons_sft=FALSE;
  75. static int      term_kan=0;
  76. static int      term_sft=FALSE;
  77. /* --------------- RSB for L20  93. 1.20 Pumpkin ------------- */
  78. static int      neednt_close=FALSE;
  79. /* ---------------------------------------------------------- */
  80.  
  81. void    send_aux();
  82. void    send_str();
  83.  
  84. /*--------------- Fast Down 92/03/23 Pumpkin  ----------------*/
  85. void    send_one_flush();
  86. void    send_one(int ch);
  87. /* ---------------------------------------------------------- */
  88.  
  89. /*------ Bplus Xmodem/1024/SUM/CRC 92/02/17 Pumpkin  ---------*/
  90. #include    "xmodem2.c"
  91. /******
  92. #include    "xmodem.c"
  93. *****/
  94. /*------------------------------------------------------------*/
  95.  
  96. #ifdef    TOWNS
  97. /* --------------- RSB for L20  92.12.27 Pumpkin ------------- */
  98. extern    char *getCMOSpara();
  99. void RSB_start()
  100. {
  101.  
  102.     char *rsb_para;
  103.  
  104.     rsb_para = getCMOSpara();
  105.     RSB_Init();
  106.  
  107.     if (rsb_para == NULL) return;
  108.     mode = rsb_para[0x63];             /*  通信モード           */
  109.     bps  = rsb_para[0x62];               /*  ボーレート          */
  110. }
  111. /* ---------------------------------------------------------- */
  112. /******
  113. void    Test_RSB_mode()
  114. {
  115.     static short flg=FALSE;
  116.     RSB_PARA rsb_para;
  117.  
  118.     if ( flg != FALSE )
  119.     return;
  120.     flg = TRUE;
  121.  
  122.     RSB_Rdpara(port,(char *)&rsb_para);
  123.     mode = rsb_para.mode;
  124.     bps  = rsb_para.baud;
  125. }
  126. *****/
  127. void    RSB_init(pt,md,bp)
  128. int    pt,md,bp;
  129. {
  130.  
  131.     WORD(buffer+0) = BUF_SIZ;
  132.     BYTE(para+0) = md;
  133.     BYTE(para+1) = bp;
  134.     DWORD(para+2) = (unsigned int)buffer;
  135.     WORD(para+6) = 0x14;
  136.     WORD(para+8) = 0;
  137.     WORD(para+10) = 0;
  138.     DWORD(para+12) = 0;
  139.     WORD(para+16) = 0;
  140.  
  141. /* --------------- RSB for L20  93. 1.20 Pumpkin ------------- */
  142.     if (neednt_close==FALSE) {
  143.         RSB_Dtr(pt,1);        /* DTR信号の保持 */
  144.         RSB_Close(pt);
  145.     }
  146. /* ---------------------------------------------------------- */
  147. /******
  148.     RSB_Dtr(pt,1);        /+ DTR信号の保持 +/
  149.     RSB_Close(pt);
  150. ******/
  151.     RSB_Setpara(pt, para);
  152.     RSB_Open(pt);
  153. }
  154. #endif
  155.  
  156. /*********************************************************
  157. 012345678901234567890123456789012345678901234567890123
  158.           1         2         3         4         5
  159.            *     *     *     *     *     *     *
  160. ポ-トNo.    0     1     2     3     4
  161. 速  度     300   600   1200  2400  4800  9600  19200
  162. ビット長     7ビット 8ビット
  163. パリティ-     無し  偶数  奇数
  164. ストップビット  1ビット 2ビット
  165. フロ-制御    無し  XON/OFF
  166. ブレ-ク時間  250ms 500ms 1sec  2sec
  167. 文字色     青色  赤色  紫色  緑色  水色  黄色  白色
  168. 文字制御   有り  無し  表示
  169. 改行待ち   無し  50ms  100ms 200ms 500ms
  170. 漢字コ-ド SJIS  EUC   JIS
  171. **********************************************************/
  172. void    Set_RSB_mode(x,y)
  173. int    x,y;
  174. {
  175.     unsigned int ec;
  176.     int    i,n,no,ch,cl,fg;
  177.     char   tmp[160];
  178.     static int  pt,bp,bit,party,stop,xfls,br,col,ctl,swt,km;
  179.     static struct {
  180.     int     *flg_mn;
  181.     int     max_mn;
  182.     char    *ttl_mn;
  183.     char    *sub_mn[8];
  184.     } MODE_menu[]={
  185. { &pt,5,"ポ-トNo.   ","0","1","2","3","4" },
  186. { &bp,7,"速  度    ","300","600","1200","2400","4800","9600","19200"},
  187. { &bit,2,"ビット長    ","7ビット","8ビット" },
  188. { &party,3,"パリティ-    ","なし","奇数","偶数" },
  189. { &stop,2,"ストップビット ","1ビット","2ビット" },
  190. { &xfls,2,"フロ-制御   ","なし","あり" },
  191. { &br,4,"ブレ-ク時間 ","250ms","500ms","1sec","2sec" },
  192. { &col,7,"文字色    ","青色","赤色","紫色","緑色","水色","黄色","白色" },
  193. { &ctl,3,"文字制御  ","有り","無し","表示" },
  194. { &swt,5,"改行WAIT  ","無し","50ms","100ms","200ms","500ms" },
  195. { &km, 3,"漢字コ-ト   ","SJIS","EUC","JIS" }
  196.     };
  197.  
  198.     pt = port;
  199.     bp = bps;
  200.     bit = ((mode & 0x01) == 0 ? 0 : 1);
  201.     party = ((mode & 0x02) == 0 ? 0 : ((mode & 0x04) == 0 ? 1 : 2));
  202.     stop = ((mode & 0x08) == 0 ? 0 : 1);
  203.     xfls = ((mode & 0x10) == 0 ? 0 : 1);
  204.     br = brk;
  205.     col = TrmCol-1;
  206.     ctl = DspCnt;
  207.     swt = swait;
  208.     km = KanMod;
  209.  
  210.     Dmy_form(tmp,54,0x98,0x95,0x99); 
  211.     wrtstr(tmp,x,y,0x07);
  212.     Dmy_form(tmp,54,0x96,0x20,0x96); 
  213.     for ( i = 0 ; i < MENU_MAX ; i++ )
  214.     wrtstr(tmp,x,y+i+1,0x07);
  215.     Dmy_form(tmp,54,0x9A,0x95,0x9B); 
  216.     wrtstr(tmp,x,y+MENU_MAX+1,0x07);
  217.     x += 2; y += 1;
  218.  
  219.     for ( fg = FALSE,no = 0 ; fg == FALSE ; ) {
  220.     for ( i = 0 ; i < MENU_MAX ; i++ ) {
  221.         if ( i == no ) cl = 0x14; else cl = 0x07;
  222.         wrtstr(MODE_menu[i].ttl_mn,x,y+i,cl);
  223.         for ( n = 0 ; n < MODE_menu[i].max_mn ; n++ ) {
  224.         if ( n == *(MODE_menu[i].flg_mn) ) cl = 0x14; else cl = 0x07;
  225.         wrtstr(MODE_menu[i].sub_mn[n],x+11+n*6,y+i,cl);
  226.         }
  227.     }
  228.     ch = Get_key(&ec);
  229.     if ( ch == '\x1B' || ec == 0x7200 )
  230.         goto ENDOF;
  231.         else if ( ch == '\x0D' || ec == 0x7300 )
  232.         break;    
  233.     else if ( ch == ' ' || ch == '\x1F' ) {
  234.         if ( ++no >= MENU_MAX )
  235.         no = 0;
  236.     } else if ( ch == '\x08' || ch == '\x1E' ) {
  237.         if ( --no < 0 )
  238.         no = MENU_MAX-1;
  239.     } else if ( ch == '\x1C' ) {
  240.         *(MODE_menu[no].flg_mn) += 1;
  241.         if ( *(MODE_menu[no].flg_mn) >= MODE_menu[no].max_mn )
  242.         *(MODE_menu[no].flg_mn) = 0;
  243.     } else if ( ch == '\x1D' ) {
  244.         *(MODE_menu[no].flg_mn) -= 1;
  245.         if ( *(MODE_menu[no].flg_mn) < 0 )
  246.         *(MODE_menu[no].flg_mn) = MODE_menu[no].max_mn - 1;
  247.     }
  248.     }
  249.     mode = 0;
  250.     if ( bit != 0 ) mode |= 0x01;
  251.     if ( party == 1 ) mode |= 0x02;
  252.     if ( party == 2 ) mode |= 0x06;
  253.     if ( stop != 0 ) mode |= 0x08;
  254.     if ( xfls != 0 ) mode |= 0x10;
  255.     if ( pt != port ) {
  256.     RSB_Close(port);
  257.     port = pt;
  258.     }
  259.     bps = bp;
  260.     brk = br;
  261.     TrmCol = col+1;
  262.     DspCnt = ctl;
  263.     swait = swt;
  264. /* --------------- RSB for L20  93. 1.20 Pumpkin ------------- */
  265.     neednt_close=TRUE;
  266. /* ---------------------------------------------------------- */
  267.     RSB_init(port,mode,bps);
  268. /* --------------- RSB for L20  93. 1.20 Pumpkin ------------- */
  269.     neednt_close=FALSE;
  270. /* ---------------------------------------------------------- */
  271.     KanMod = km;
  272. ENDOF:
  273. #ifdef    TOWNS
  274.     Dsp_vram_flash();
  275. #endif
  276.     Dsp_vram(cvram);
  277.     Dsp_free();
  278. }
  279.  
  280. /**********************************
  281.     RS232C Charcter Terminal
  282. ***********************************/
  283.  
  284. void    send_aux(int ch)
  285. {
  286.     unsigned st;
  287.     time_t   s,n;
  288.  
  289.     if ( RSB_Send(port,ch,&st) != 0 ) {
  290.     time(&s);
  291.     do {
  292.         if ( RSB_Send(port,ch,&st) == 0 )
  293.         break;
  294.         time(&n);
  295.     } while ( (n - s) < 5 );
  296.     }
  297. }
  298. int    recv_aux()
  299. {
  300.     int      ch;
  301.     unsigned st;
  302.  
  303.     if ( RSB_Receive(port,&ch,&st) == 0 )
  304.     return (ch & 0xff);
  305.     else
  306.     return ERR;
  307. }
  308. void    send_str(char *str,int n)
  309. {
  310.     while ( n-- > 0 )
  311.     send_aux(*(str++));
  312. }
  313. int    jis2sjis(int chr)
  314. {
  315.     int    hi,lo;
  316.  
  317.     hi = (chr >> 8) & 0xff;
  318.     lo = chr & 0xff;
  319.     if ( (hi & 1) != 0 )
  320.         lo += 0x1F;
  321.     else
  322.         lo += 0x7D;
  323.     if ( lo >= 0x7F )
  324.         lo++;
  325.     hi = (hi - 0x21 >> 1) + 0x81;
  326.     if ( hi > 0x9F )
  327.         hi += 0x40;
  328.     return (hi << 8 | lo);
  329. }
  330. int    sjis2jis(int cd)
  331. {
  332.     int    hi,lo;
  333.  
  334.     hi = (cd >> 8) & 0xff;
  335.     lo = cd & 0xff;
  336.     hi -= ( hi <= 0x9f) ? 0x71 : 0xb1;
  337.     hi = hi * 2 +1;
  338.     if ( lo > 0x7f )
  339.         lo--;
  340.     if ( lo >= 0x9e ) {
  341.         lo -= 0x7d;
  342.         hi++;
  343.     }
  344.     else
  345.         lo -= 0x1f;
  346.     return (hi << 8 | lo);
  347. }
  348. int    han2zen(int code)
  349. {
  350.     static unsigned short int ank_tbl[]={
  351.         0x8140,0x8149,0x8168,0x8194,0x8190,0x8193,0x8195,0x8166,
  352.         0x8169,0x816A,0x8196,0x817B,0x8143,0x817C,0x8144,0x815E,
  353.         0x824F,0x8250,0x8251,0x8252,0x8253,0x8254,0x8255,0x8256,
  354.         0x8257,0x8258,0x8146,0x8147,0x8183,0x8181,0x8184,0x8148,
  355.         0x8197,0x8260,0x8261,0x8262,0x8263,0x8264,0x8265,0x8266,
  356.         0x8267,0x8268,0x8269,0x826A,0x826B,0x826C,0x826D,0x826E,
  357.         0x826F,0x8270,0x8271,0x8272,0x8273,0x8274,0x8275,0x8276,
  358.         0x8277,0x8278,0x8279,0x816D,0x818F,0x816E,0x814F,0x8151,
  359.         0x8166,0x8281,0x8282,0x8283,0x8284,0x8285,0x8286,0x8287,
  360.         0x8288,0x8289,0x828A,0x828B,0x828C,0x828D,0x828E,0x828F,
  361.         0x8290,0x8291,0x8292,0x8293,0x8294,0x8295,0x8296,0x8297,
  362.         0x8298,0x8299,0x829A,0x816F,0x8162,0x8170,0x8150,0x85A1 };
  363.     static unsigned short int kana_tbl[]={
  364.         0x8140,0x8142,0x8175,0x8176,0x8141,0x8145,0x8392,0x8340,
  365.         0x8342,0x8344,0x8346,0x8348,0x8383,0x8385,0x8387,0x8362,
  366.         0x815B,0x8341,0x8343,0x8345,0x8347,0x8349,0x834A,0x834C,
  367.         0x834E,0x8350,0x8352,0x8354,0x8356,0x8358,0x835A,0x835C,
  368.         0x835E,0x8360,0x8363,0x8365,0x8367,0x8369,0x836A,0x836B,
  369.         0x836C,0x836D,0x836E,0x8371,0x8374,0x8377,0x837A,0x837D,
  370.         0x837E,0x8380,0x8381,0x8382,0x8384,0x8386,0x8388,0x8389,
  371.         0x838A,0x838B,0x838C,0x838D,0x838F,0x8393,0x814A,0x814B };
  372.  
  373.     code &= 0xFF;
  374.     if ( 0x20 <= code && code <= 0x7F )
  375.         return ank_tbl[code-0x20];
  376.     else if ( 0xA0 <= code && code <= 0xDF )
  377.         return kana_tbl[code-0xA0];
  378.     else
  379.         return 0x85A1;
  380. }
  381. void    send_shift(int sw)
  382. {
  383.     if ( sw != term_sft ) {
  384.         term_sft = sw;
  385.         send_str((sw == FALSE ? "\033(J":"\033$@"),3);
  386.     }
  387. }
  388. void    Send_char(int ch)
  389. {
  390.     ch &= 0xFF;
  391.  
  392.     switch(KanMod) {
  393.     case SJIS:
  394.         send_aux(ch);
  395.         break;
  396.  
  397.     case JIS:
  398.         if ( term_kan != 0 ) {
  399.             if ( iskanji2(ch) ) {
  400.                 ch |= (term_kan << 8);
  401.                 ch = sjis2jis(ch);
  402.                 send_shift(TRUE);
  403.                 send_aux(ch >> 8);
  404.                 send_aux(ch & 0xFF);
  405.                 term_kan = 0;
  406.                 break;
  407.  
  408.             } else {
  409.                 term_kan = sjis2jis(han2zen(term_kan));
  410.                 send_shift(TRUE);
  411.                 send_aux(term_kan >> 8);
  412.                 send_aux(term_kan & 0xFF);
  413.                 term_kan = 0;
  414.             }
  415.         }
  416.  
  417.         if ( iskanji(ch) )
  418.             term_kan = ch;
  419.         else if ( (ch & 0x80) != 0 ) {
  420.             ch = sjis2jis(han2zen(ch));
  421.             send_shift(TRUE);
  422.             send_aux(ch >> 8);
  423.             send_aux(ch & 0xFF);
  424.         } else {
  425.             send_shift(FALSE);
  426.             send_aux(ch);
  427.         }
  428.         break;
  429.  
  430.     case EUC:
  431.         if ( term_kan != 0 ) {
  432.             if ( iskanji2(ch) ) {
  433.                 ch |= (term_kan << 8);
  434.                 ch = sjis2jis(ch);
  435.                 ch |= 0x8080;
  436.                 send_aux(ch >> 8);
  437.                 send_aux(ch & 0xFF);
  438.                 term_kan = 0;
  439.                 break;
  440.  
  441.             } else {
  442.                 term_kan = sjis2jis(han2zen(term_kan));
  443.                 term_kan |= 0x8080;
  444.                 send_aux(term_kan >> 8);
  445.                 send_aux(term_kan & 0xFF);
  446.                 term_kan = 0;
  447.             }
  448.         }
  449.  
  450.         if ( iskanji(ch) )
  451.             term_kan = ch;
  452.         else if ( (ch & 0x80) != 0 ) {
  453.             ch = sjis2jis(han2zen(ch));
  454.             ch |= 0x8080;
  455.             send_aux(ch >> 8);
  456.             send_aux(ch & 0xFF);
  457.         } else
  458.             send_aux(ch);
  459.         break;
  460.     }
  461.  
  462.     if ( ch == 0x0D && swait != 0 )
  463.     Soft_Timer(swtime[swait]);
  464. }
  465.  
  466. void    Send_cons(int ch)
  467. {
  468.     ch &= 0xFF;
  469.  
  470.     switch(KanMod) {
  471.     case SJIS:
  472.         send_one(ch);
  473.         break;
  474.  
  475.     case JIS:
  476.         ch &= 0x7F;
  477.         if ( cons_kan != 0 ) {
  478.             if ( cons_sft == FALSE || ch < ' ' ) {
  479.                 send_one(cons_kan);
  480.                 cons_kan = 0;
  481.             } else {
  482.                 cons_od2 = cons_od1;
  483.                 cons_od1 = ch;
  484.                 ch |= (cons_kan << 8);
  485.                 ch &= 0x7F7F;
  486.                 ch = jis2sjis(ch);
  487.                 send_one(ch >> 8);
  488.                 send_one(ch & 0xFF);
  489.                 cons_kan = 0;
  490.                 break;
  491.             }
  492.         }
  493.  
  494.         if ( ch < ' ' ) {
  495.             cons_sft = FALSE;
  496.             send_one(ch);
  497.         } else if ( cons_sft != FALSE ) {
  498.             cons_kan = ch;
  499.         } else {
  500.             send_one(ch);
  501.         }
  502.  
  503.         if ( (ch == 'B' || ch == '@') &&
  504.              cons_od1 == '$' && cons_od2 == '\033' )
  505.             cons_sft = TRUE;
  506.         else if ( (ch == 'B' || ch == 'J') &&
  507.              cons_od1 == '(' && cons_od2 == '\033' )
  508.             cons_sft = FALSE;
  509.  
  510.         cons_od2 = cons_od1;
  511.         cons_od1 = ch;
  512.         break;
  513.  
  514.     case EUC:
  515.         if ( cons_kan != 0 ) {
  516.             if ( (ch & 0x80) != 0 ) {
  517.                 ch |= (cons_kan << 8);
  518.                 ch &= 0x7F7F;
  519.                 ch = jis2sjis(ch);
  520.                 send_one(ch >> 8);
  521.                 send_one(ch & 0xFF);
  522.                 cons_kan = 0;
  523.                 break;
  524.             }
  525.             send_one(cons_kan);
  526.             cons_kan = 0;
  527.         }
  528.         if ( (ch & 0x80) != 0 )
  529.             cons_kan = ch;
  530.         else
  531.             send_one(ch);
  532.         break;
  533.     }
  534. }
  535. void    recv_chk()
  536. {
  537.     int         ch,len;
  538.     unsigned st;
  539.  
  540.     RSB_Read(port,&len);
  541.     if ( len <= 0 )
  542.     return;
  543.  
  544.     while ( len > 0 ) {
  545.     if ( RSB_Receive(port,&ch,&st) != 0 )
  546.         break;
  547.  
  548.         if ( ch == 0x05 ) {     /* ENQ Then B Plus Protocol Start ? */
  549.         BP_Term_ENQ();
  550.         break;
  551.     } if ( ch == 0x10 ) {    /* DLE Then B Plus Protocol Start ? */
  552.         BP_DLE_Seen();
  553.         break;
  554.     } else
  555.         Send_cons(ch);
  556.  
  557.     len--;
  558.     }
  559.  
  560.     Dsp_vram(cvram);
  561. }
  562. void    Dsp_RSBKEY()
  563. {
  564.     int     i;
  565.     static char *menu[]={
  566.     " 設定 "," 入力 "," AUTO ","      ","CD演奏",
  567.     "ダウン","アップ"," ブレ-ク"," 終了 "," 中断 " };
  568.  
  569.     for ( i = 0 ; i < 10 ; i++ )
  570.         wrtstr(menu[i],i*7+(i/5),MENU_Y,0x16);
  571. }
  572. void    Down_load()
  573. {
  574.     int    x,y;
  575.     char   tmp[80];
  576.     static int  no=ERR;
  577. /* --------------XMODEM 1024/SUM/CRC 92/02/17 Pumpkin --------------- */
  578.     static char *menu[]={
  579.     "1 編集バッファに (新規)    ",
  580.     "2 編集バッファに (追加)    ",
  581.     "",
  582.     "3 ファイルに(新規/追加)    ",
  583.     "",
  584.     "4 X-MODEM/SUMでダウンする  ",
  585.     "5 X-MODEM/SUMでダウン(高速)",
  586.     "6 X-MODEM/CRCでダウン      ",
  587.     "7 Y-MODEM/1024でダウン     ",
  588.     "8 Y-MODEM-gでダウン        ",
  589.     NULL };
  590. /**********
  591.     static char *menu[]={
  592.     "1 編集バッファに (新規) ",
  593.     "2 編集バッファに (追加) ",
  594.     "",
  595.     "3 ファイルに(新規/追加) ",
  596.     "",
  597.     "4 X-Modemでダウンする   ",
  598.     "5 X-Modemでダウン(高速) ",
  599.     NULL };
  600. *********/
  601. /* ---------------------------------------------------------------- */
  602.  
  603.     wrtstr(SPCSTR,30,1,0x1F);
  604.     if ( Down_flg != FALSE || Down_fp != NULL ) {
  605.     if ( Down_fp != NULL ) {
  606.         fputc('\x1A',Down_fp);
  607.         fclose(Down_fp);
  608.         Down_fp = NULL;
  609.     }
  610. /* --------------- Fast Down 92/03/23 Pumpkin  ---------------- */
  611.         send_one_flush();
  612. /* ------------------------------------------------------------ */
  613.     Down_flg = FALSE;
  614.     wrtstr("                  ",32,0,0x1F);
  615.     return;
  616.     }
  617.  
  618.     if ( Sel_menu(menu,25,2,&no) != FALSE )
  619.     goto ENDOF;
  620.  
  621.     if ( no == 0 ) {
  622.     Del_buf(0l,btm_ptr);
  623.     top_ptr = lin_ptr = ent_ptr = btm_ptr = 0;
  624.     Line_no = 0;
  625.         Down_flg = TRUE;
  626.     } else if ( no == 1 ) {
  627.         x = Cur_X; y = Cur_Y;
  628.         Cur_btm_file();
  629.         Cur_X = x; Cur_Y = y;
  630.         Down_flg = TRUE;
  631. /* ------------------ Bug Fix  91.04.20 Pumpkin ----------------- */
  632.     ent_ptr = btm_ptr;
  633. /* -------------------------------------------------------------- */
  634.     } else if ( no == 2 ) {
  635.     tmp[0] = '\0';
  636.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  637.         goto ENDOF;
  638.     if ( (Down_fp = fopen(tmp,"ab+")) == NULL ) {
  639.         wrtstr("(ファイルがオ-プン出来ません)",30,1,0x12);
  640.         goto ENDOF;
  641.     }
  642. /* --------------XMODEM 1024/SUM/CRC 92/02/17 Pumpkin --------------- */
  643.     } else if ( no == 3 || no == 4 || no == 5 ) {
  644.     tmp[0] = '\0';
  645.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  646.         goto ENDOF;
  647.     if ( no == 4 ) Flaing = TRUE; else Flaing = FALSE;
  648.     if ( no == 5 ) crcmode = TRUE; else crcmode = FALSE;
  649.         Dsp_vram(cvram);
  650.         RSB_init(port,mode & 0xEF,bps);
  651.     Down_Xmodem(tmp);
  652.         RSB_init(port,mode,bps);
  653.     goto ENDOF;
  654.     } else if ( no == 6 || no == 7 ) {
  655.     if ( no == 6 ) Flaing = FALSE; else Flaing = TRUE;
  656.         Dsp_vram(cvram);
  657.         RSB_init(port,mode & 0xEF,bps);
  658.     Down_Ymodem();
  659.         RSB_init(port,mode,bps);
  660.     goto ENDOF;
  661. /*****
  662.     } else if ( no == 3 || no == 4 ) {
  663.     tmp[0] = '\0';
  664.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  665.         goto ENDOF;
  666.     Flaing = (no == 3 ? FALSE : TRUE);
  667.         RSB_init(port,mode & 0xEF,bps);
  668.     Down_Xmodem(tmp);
  669.         RSB_init(port,mode,bps);
  670.     goto ENDOF;
  671. *****/
  672. /* -------------------------------------------------------------- */
  673.     }
  674.     wrtstr("ダウンロ-ド実行中",32,0,0x15);
  675. ENDOF:
  676.     Dsp_vram(cvram);
  677.     Dsp_free();
  678. }
  679. void    Up_load()
  680. {
  681.     int        ch,i,n,ct;
  682.     unsigned int ec;
  683.     FILE   *fp;
  684.     char   tmp[256];
  685.     char   *p;
  686.     LONG   ptr,sz;
  687.     static int  no=ERR;
  688. /* ------------XMODEM 1024/SUM/CRC 92/02/17 Pumpkin ------------- */
  689.     static char *menu[]={
  690.     "1 編集バッファをアップ    ",
  691.     "2 Undoバッファをアップ    ",
  692.     "",
  693.     "3 ファイルをアップする    ",
  694.     "",
  695.     "4 X-MODEM/SUMでアップする ",
  696.     "5 X-MODEM/CRCでアップする ",
  697.     NULL };
  698. /*****
  699.     static char *menu[]={
  700.     "1 編集バッファをアップ  ",
  701.     "2 Undoバッファをアップ  ",
  702.     "",
  703.     "3 ファイルをアップする  ",
  704.     "",
  705.     "4 X-Modemでアップする   ",
  706.     NULL };
  707. *****/
  708. /* -------------------------------------------------------------- */
  709.  
  710.     wrtstr(SPCSTR,30,1,0x1F);
  711.     if ( Sel_menu(menu,30,2,&no) != FALSE )
  712.     goto ENDOF;
  713.  
  714.     if ( no == 0 ) {
  715.     ptr = 0;
  716.     sz = btm_ptr;
  717.     n = i = 0;
  718.     } else if ( no == 1 ) {
  719.     ptr = 0;
  720.     n = 0;
  721.     } else if ( no == 2 ) {
  722.     tmp[0] = '\0';
  723.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  724.         goto ENDOF;
  725.     if ( (fp = fopen(tmp,"rb")) == NULL ) {
  726.         wrtstr("(ファイルがオ-プン出来ません)",30,1,0x12);
  727.         goto ENDOF;
  728.     }
  729. /* ------------XMODEM 1024/SUM/CRC 92/02/17 Pumpkin ------------- */
  730.     } else if ( no == 3  || no == 4 ) {
  731. /*****
  732.     } else if ( no == 3 ) {
  733. *****/
  734. /* -------------------------------------------------------------- */
  735.     tmp[0] = '\0';
  736.     if ( Input(tmp,"ファイル名 ") != FALSE || File_sel(tmp) != FALSE )
  737.         goto ENDOF;
  738.         RSB_init(port,mode & 0xEF,bps);
  739. /* ------------XMODEM 1024/SUM/CRC 92/02/17 Pumpkin ------------- */
  740.     if ( no == 3 ) {
  741.         crcmode= FALSE;
  742.     } else {
  743.         crcmode= TRUE;
  744.     }
  745.     Dsp_vram(cvram);
  746. /* -------------------------------------------------------------- */
  747.     Up_Xmodem(tmp);
  748.         RSB_init(port,mode,bps);
  749.     goto ENDOF;
  750.     }
  751.  
  752.     wrtstr("アップロ-ド実行中",32,1,0x14);
  753.     Dsp_vram(cvram);
  754.     for ( ct = 0 ; ; ct++ ) {
  755.     if ( kbhit() != 0 ) {
  756.         ch = Get_key(&ec);
  757.         if ( ch == 0x1B || ec == 0x7200 )
  758.         break;
  759.     }
  760.     if ( no == 0 ) {
  761.         if ( i >= n ) {
  762.             if ( sz <= 0 )
  763.             break;
  764.         if ( sz < 256 ) n = sz; else n = 256;
  765.         Cut_buf(tmp,n,ptr);
  766.         ptr += n;
  767.         sz -= n;
  768.         i = 0;
  769.         }
  770.         ch = tmp[i++];
  771.     } else if ( no == 1 ) {
  772.         if ( n <= 0 ) {
  773.         if ( (n = Undo_cpy(tmp,256,ptr)) == 0 )
  774.             break;
  775.         p = tmp;
  776.         ptr += n;
  777.         }
  778.         ch = *(p++); n--;
  779.     } else if ( no == 2 ) {
  780.         if ( (ch = fgetc(fp)) == EOF )
  781.         break;
  782.     }
  783.     if ( ct > 50 ) {
  784.         recv_chk();
  785.         ct = 0;
  786.         }
  787.     if ( ch != '\x0A' && ch != '\x1A' )
  788.         Send_char(ch & 0xff);
  789.     }
  790.     if ( no == 3 )
  791.     fclose(fp);
  792.     wrtstr(SPCSTR,30,1,0x1F);
  793. ENDOF:
  794.     Dsp_vram(cvram);
  795.     Dsp_free();
  796. }
  797. void    RSB_end()
  798. {
  799. /* --------------- RSB for L20  93. 1.20 Pumpkin ------------- */
  800.     if ( cvram != NULL ) {
  801.     neednt_close=TRUE;
  802.         RSB_Close(port);
  803.     }
  804. /* ---------------------------------------------------------- */
  805. /*********
  806.     if ( cvram != NULL )
  807.         RSB_Close(port);
  808. ********/
  809.     wrtstr("    ",10,0,0x1F);
  810.     free(cvram);
  811.     cvram = NULL; 
  812. }
  813.  
  814. /* ------------------ 1l Input 93/02/10 Pumpkin ---------------- */
  815.  
  816. extern void MOJI_input1Char(UCHAR *moji_area
  817.         ,unsigned int ky,int max_moji,int *lcur_x);
  818.  
  819.  
  820. void    Line_edit(int ch,unsigned int ec,int *lcur_x)
  821. {
  822.     static unsigned char Line_tmp[81]={0};
  823.     int        len,i;
  824.     char    tmp[81],tmp2[3];
  825.  
  826.  
  827.     if ( Line_flg == FALSE ) {    /* 非一行入力状態 */
  828.     if ( ch != 0xFFFF )
  829.         Send_char(ch & 0xff);
  830.     if ( Line_X > 0 ) {
  831.         Line_X = 0;        /* 入力行の消去  */
  832.         *lcur_x=0;
  833.         memset(Line_tmp,' ',80); Line_tmp[80] = 0;
  834.         wrtstr(Line_tmp,0,MAX_Y2+OFF_Y,0);
  835.     }
  836.     return;
  837.     }
  838.  
  839.     if ( ch == 0xFFFF ) {    /* 初期化  */
  840.     Line_tmp[0]=0;
  841.         Line_X = len = *lcur_x=0;
  842.         goto jump;
  843.  
  844.     }
  845.  
  846.     if (Line_X == 0 && ch < ' ') {
  847.     Send_char(ch & 0xff);
  848.         goto jump;
  849.     }
  850.  
  851.     MOJI_input1Char(Line_tmp,(unsigned int)ch,80,lcur_x);
  852.     Line_X = len = strlen(Line_tmp);
  853.     if ( ch == '\x0D' || ec == 0x7300 ) {    /* 送信 */
  854.     for ( i = 0 ; i < len ; i++ ) Send_char(Line_tmp[i] & 0xff);
  855.     Send_char(0x0D);
  856.     Line_tmp[0]=0;
  857.         Line_X = len = *lcur_x = 0;
  858.     } else if ( ch == '\x0B' || ch == '\x1B' || ec == 0x7200) {
  859.     Line_tmp[0]=0;
  860.         Line_X = len = *lcur_x = 0;
  861.     } else if ( ec == 0x4f04) {
  862.         *lcur_x=0;
  863.     } else if ( ec == 0x5104) {
  864.     *lcur_x = strlen(Line_tmp);
  865.     }
  866.  
  867. jump:
  868.     strcpy(tmp,Line_tmp);        /* 文字表示 */
  869.     memset(tmp+len,' ',81-len);
  870.     tmp[80]=0;
  871.     wrtstr(tmp,0,MAX_Y2+OFF_Y,0x1D);
  872.  
  873.     if (*lcur_x == len) {        /* カーソル表示 */
  874.     tmp2[0] = 0xFE;
  875.     tmp2[1] = 0x1B;
  876.     tmp2[2] = 0;
  877.     wrtstr(tmp2,*lcur_x,MAX_Y2+OFF_Y,0x1D);
  878.     }else{
  879.     if (iskanji(Line_tmp[*lcur_x])) {
  880.         tmp2[0] = Line_tmp[*lcur_x];
  881.         tmp2[1] = Line_tmp[*lcur_x+1];
  882.         tmp2[2] = 0;
  883.     }else{
  884.         tmp2[0] = Line_tmp[*lcur_x];
  885.         tmp2[1] = 0;
  886.     }
  887.     wrtstr(tmp2,*lcur_x,MAX_Y2+OFF_Y,0x17);
  888.     }
  889.     ReWrt_flg = (-2);
  890.  
  891. }
  892. /*********
  893. void    Line_edit(ch)
  894. int     ch;
  895. {
  896.     int    i;
  897.     static char tmp[180];
  898.  
  899.     if ( Line_flg == FALSE ) {
  900.     if ( ch != 0xFFFF )
  901.         Send_char(ch & 0xff);
  902.     if ( Line_X > 0 ) {
  903.         Line_X = 0;
  904.         memset(tmp,' ',80); tmp[80] = 0;
  905.         wrtstr(tmp,0,MAX_Y2+OFF_Y,0);
  906.         wrtstr(tmp,0,MAX_Y2+OFF_Y+1,0);
  907.     }
  908.     return;
  909.     }
  910.     if ( ch == 0x08 && Line_X > 0 ) {
  911.     Line_X--;
  912.     if ( &tmp[Line_X] != kanji_chk(tmp,Line_X) )
  913.        Line_X--;
  914.     } else if ( Line_X == 0 && ch < ' ' ) {
  915.     Send_char(ch & 0xff);
  916.     } else if ( ch != 0x08 && ch != 0x1B && ch != 0xFFFF )
  917.         tmp[Line_X++] = ch;
  918.     if ( Line_X >= 158 || ch == 0x0D || ch == 0x1B ) {
  919.     for ( i = 0 ; i < Line_X ; i++ )
  920.         Send_char(tmp[i] & 0xff);
  921.     if ( Line_X >= 80 ) {
  922.         memset(tmp,' ',80); tmp[80] = 0;
  923.         wrtstr(tmp,0,MAX_Y2+OFF_Y+1,0);
  924.     }
  925.     Line_X = 0;
  926.     }
  927.     tmp[Line_X] = 0xFE; tmp[Line_X+1] = 0x1B;
  928.     memset(tmp+Line_X+2,' ',164-Line_X);
  929.     tmp[161] = 0;
  930.     if ( Line_X < 80 )
  931.         tmp[81] = '\0';
  932.     wrtstr(tmp,0,MAX_Y2+OFF_Y,0x1D);
  933.     ReWrt_flg = (-2);
  934. }
  935. ********/
  936. /* ---------------------------------------------------------- */
  937.  
  938. void    RSB_loop()
  939. {
  940.     int     ch,ef;
  941.     int     Bk_X,Bk_Y;
  942.     unsigned ec;
  943. /* ------------------ 1l Input 93/02/10 Pumpkin ---------------- */
  944.     int    lcur_x=0;
  945. /* ---------------------------------------------------------- */
  946.  
  947.     wrtstr(SPCSTR,30,1,0x1F);
  948.     if ( cvram == NULL ) {
  949. /* --------------- RSB for L20  92.12.27 Pumpkin ------------- */
  950. /*******
  951.         Test_RSB_mode();
  952. *******/
  953. /* ---------------------------------------------------------- */
  954.         RSB_init(port,mode,bps);
  955. /* --------------- RSB for L20  93. 1.20 Pumpkin ------------- */
  956.     neednt_close=FALSE;
  957. /* ---------------------------------------------------------- */
  958.     }
  959.     if ( Con_init() != FALSE ) {
  960.         RSB_Close(port);
  961.     return;
  962.     }
  963.     wrtstr("通信",10,0,0x17);
  964.     Dsp_RSBKEY();
  965.  
  966. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  967.     cd_m_stat = TRUE;
  968. /* ---------------------------------------------------------- */
  969.     for ( ef = FALSE ; ef == FALSE ; ) {
  970.     recv_chk();
  971.     for ( ; ; ) {
  972. /* ------------------ 1l Input 93/02/10 Pumpkin ---------------- */
  973.         if ( Line_flg != FALSE ) {
  974.             Bk_X = Cur_X; Bk_Y = Cur_Y;
  975.         Cur_X = lcur_x; Cur_Y = MAX_Y2;
  976.         if ( ReWrt_flg == ERR )
  977.             ReWrt_flg = TRUE;
  978.         }
  979. /********
  980.         if ( Line_flg != FALSE ) {
  981.             Bk_X = Cur_X; Bk_Y = Cur_Y;
  982.             Cur_X = Line_X % 80; Cur_Y = MAX_Y2 + Line_X / 80;
  983.         if ( ReWrt_flg == ERR )
  984.             ReWrt_flg = TRUE;
  985.         }
  986. **********/
  987. /* ---------------------------------------------------------- */
  988.         if ( kbhit() != 0 )
  989.             ch = Get_key(&ec);
  990.         else
  991.         ec = 0xFFFF;
  992.         if ( Line_flg != FALSE ) {
  993.             Cur_X = Bk_X; Cur_Y = Bk_Y;
  994.         }
  995.         if ( ec == 0xFFFF )
  996.         break;
  997.         else if ( ec == 0x6600 )
  998.         ef = TRUE;
  999.         else if ( ec == 0x6500 )
  1000.         ef = ERR;
  1001.         else if ( ec == 0x5D00 )
  1002.         Set_RSB_mode(1,2);
  1003.         else if ( ec == 0x5E00 ) {
  1004.         Line_flg = (Line_flg == FALSE ? TRUE : FALSE);
  1005.         if ( Line_flg == FALSE )
  1006.             Line_X = 1;
  1007.         Line_edit(0xFFFF,0,&lcur_x);
  1008.         } else if ( ec == 0x5F00 )
  1009.         Auto_log();
  1010.         else if ( ec == 0x6100 ) {
  1011. #ifdef    TOWNS
  1012.         CD_menu();
  1013. #endif
  1014.             Dsp_vram(cvram);
  1015.         } else if ( ec == 0x6200 )
  1016.         Down_load();
  1017.         else if ( ec == 0x6300 )
  1018.         Up_load();
  1019.         else if ( ec == 0x6400 )
  1020.         RSB_Break(port,brktime[brk]);
  1021.         else if ( ch != 0xFFFF )
  1022.         Line_edit(ch,ec,&lcur_x);
  1023.     }
  1024.     }
  1025.     Con_end();
  1026.     if ( Down_flg != FALSE )
  1027.     Down_load();
  1028.     if ( ef == ERR )
  1029.     RSB_end();
  1030.     else
  1031.         wrtstr("通信",10,0,0x1F);
  1032.     Dsp_PFKEY();    
  1033.  
  1034.     Line_flg = FALSE; Line_X = 1;
  1035.     Line_edit(0xFFFF,0,&lcur_x);
  1036.  
  1037. /* --------------- RED2 Like   92.01.31 Pumpkin ------------- */
  1038.     cd_m_stat = FALSE;
  1039. /* ---------------------------------------------------------- */
  1040.     wrtstr(SPCSTR,30,1,0x1F);
  1041. }
  1042.  
  1043. /*--------------- Fast Down 92/03/23 Pumpkin  ----------------*/
  1044. static  char    sc_tmp[520];
  1045. static  int    n = 0;
  1046. void    send_one_flush()
  1047. {
  1048.     int     x,y;
  1049.  
  1050.     if ( Down_flg != FALSE && n != 0 ) {
  1051.     x = Cur_X; y = Cur_Y;
  1052.         ins_chr(sc_tmp,n);
  1053.     Set_vram();
  1054.     Dsp_free();
  1055.     Cur_X = x; Cur_Y = y;
  1056.     n = 0;
  1057.     }
  1058. }
  1059.  
  1060. void    send_one(int ch)
  1061. {
  1062.  
  1063.     BakPut(ch);
  1064.  
  1065.     if ( Down_fp != NULL && ch != '\x08' && ch != '\0' )
  1066.     fputc(ch,Down_fp);
  1067.  
  1068.     if ( Down_flg != FALSE && ch != '\0' && ch != '\x0D' ) {
  1069.     if ( ch == '\x0A' )
  1070.         sc_tmp[n++] = 0x0D;
  1071.     sc_tmp[n++] = ch;
  1072.     if (n >= 512) send_one_flush();
  1073.     }
  1074. }
  1075. /* ---------------------------------------------------------- */
  1076.  
  1077.